package lib.JButtonTable;

import app.MyTable;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

/**
 * @version 1.0 11/09/98
 */
public class ButtonRenderer extends JButton implements TableCellRenderer {

    protected JButton disabledButton = new JButton();
    private ButtonModel bmodel = null;
    
    public ButtonModel getBModel(){
        return bmodel;
    }
    
    public ButtonRenderer() {
        setOpaque(true);
        this.disabledButton.setEnabled(false);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            setBackground(UIManager.getColor("Button.background"));
        }
        
        bmodel = (ButtonModel) value;
        
        if(this.isButtonEnable()){
            return this;
        }else{
            ((MyTable) table).disableButtonCell(row, column);
            return disabledButton;
        }
    }
    
    protected boolean isButtonEnable(){
        return bmodel.isEnable();
    }

    @Override
    public void setText(String text) {
        super.setText(text);
        this.disabledButton.setText(text);
    }
    
}